//
// ContentDispositionTest.cs - NUnit Test Cases for Xtee.Net.Mime.ContentDisposition
//
// Authors:
//   John Luke (john.luke@gmail.com)
//
// (C) 2005 John Luke
//
 

using NUnit.Framework;
using System;
using Xtee.Core.Mime;



namespace Xtee.Core.Test.Mime.DataTypes
{
    [TestFixture]
    public class ContentDispositionTest :TestBase
    {
        ContentDisposition cd;
		
        [SetUp]
        public void GetReady ()
        {
            
            cd = new ContentDisposition ();
            cd.FileName = "genome.jpeg";
            cd.ModificationDate = DateTime.MaxValue;
        }


        [Test]
        public void DispositionType ()
        {
            Assert.AreEqual ("attachment", cd.DispositionType);
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void DispositionTypeNull ()
        {
            cd.DispositionType = null;
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void DispositionTypeEmpty ()
        {
            cd.DispositionType = "";
        }

        [Test]
        public void EqualsHashCode ()
        {
            ContentDisposition dummy1 = new ContentDisposition ();
            dummy1.Inline = true;
            ContentDisposition dummy2 = new ContentDisposition ("inline");
            Assert.IsTrue (dummy1.Equals (dummy2));
            Assert.IsFalse (dummy1 == dummy2);
            Assert.IsTrue (dummy1.GetHashCode () == dummy2.GetHashCode ());
        }

        [Test]
        public void Equals ()
        {
            ContentDisposition dummy1 = new ContentDisposition ();
            dummy1.FileName = "genome.jpeg";
            ContentDisposition dummy2 = new ContentDisposition ("attachment; filename=genome.jpeg");
            Assert.IsTrue (dummy1.Equals (dummy2));
        }

        [Test]
        public void FileName ()
        {
            Assert.AreEqual ("genome.jpeg", cd.FileName);
        }

        [Test]
        public void Size ()
        {
            Assert.AreEqual (-1, cd.Size);
        }

        [Test]
        [ExpectedException(typeof(FormatException), ExpectedMessage = "Invalid disposition-type : Attachment or Inline are valid values")]
        public void InvalidFormatException()
        {
            ContentDisposition dummy1 = new ContentDisposition();
            dummy1.DispositionType = "wrong disposion type";
        }
        [Test]
        [ExpectedException(typeof(FormatException), ExpectedMessage = "Invalid disposition-type : Attachment or Inline are valid values")]
        public void InvalidFormatException2()
        {
            new ContentDisposition("attachmentwrong; filename=genome.jpeg");
          
        }

        [ExpectedException(typeof(ArgumentNullException))]
        public void ArgumentNullException()
        {
            new ContentDisposition(null);
        }


        [Test]
        [ExpectedException (typeof (FormatException))]
        public void FormatException ()
        {
            new ContentDisposition ("");
        }

        [ExpectedException(typeof(FormatException), ExpectedMessage = "Unsupported Content-Disposition parameter: foo")]
        [Test]
        public void UnexpectedParameterException()
        {
            new ContentDisposition ("attachment; foo=bar");
        }

        [Test]
        public void IsInline ()
        {
            Assert.IsFalse (cd.Inline);
        }

        [Test]
        public void Parameters ()
        {
            Assert.IsNotNull (cd.Parameters, "is not null");
            Assert.AreEqual (2, cd.Parameters.Count);
        }

	
        [Test]
        public void ToStringTest2 ()
        {
            ContentDisposition dummy = new ContentDisposition ();
            Assert.AreEqual ("attachment", dummy.ToString ());
        }

        [Test]
        public void ToStringTest3 ()
        {
            ContentDisposition dummy = new ContentDisposition ();
            dummy.Size = 0;
            Assert.AreEqual ("attachment; size=0", dummy.ToString ());
        }

        [Test]
        public void ToStringTest4 ()
        {
            ContentDisposition dummy = new ContentDisposition ("attachment");
            dummy.Parameters.Add ("foo", "bar");
            Assert.AreEqual (1, dummy.Parameters.Count);
            Assert.AreEqual ("attachment; foo=bar", dummy.ToString ());
        }
    }
}